package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.dto.StuQueryRequest;
import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Select("select * from student where clazz_id=#{clazzId}")
    List<Student> getByClassId(Integer clazzId);

    Page<Student> pageByNameAndDegreeAndClassId(StuQueryRequest request);

    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, create_time, update_time) values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    @Select("select * from student where id=#{id}")
    Student getById(Integer id);

    @Update("update student set name=#{name},no=#{no},gender=#{gender},phone=#{phone},id_card=#{idCard},is_college=#{isCollege},address=#{address},degree=#{degree},graduation_date=#{graduationDate},clazz_id=#{clazzId} where id=#{id}")
    void update(Student student);

    void deleteByIds(@Param("ids") Integer[] ids);

    @Update("update student set violation_score=#{violationScore} where id=#{id}")
    void updateScoreById(@Param("id") Integer id, @Param("violationScore") Integer score);
}
